package broadcaster;

import junit.framework.Assert;
import listener.Listener;

import org.junit.Test;

public class ListenerBroadcasterTest {
  
  private int cnt = 0;
  
  private class DummyListener implements Listener {
    public void respond(Broadcaster b) {
      ++cnt;
    }
  };
  
  private class DummyBroadcaster extends Broadcaster {
  };
  
  @Test
  public void test() {
    cnt = 0;
    Listener l = new DummyListener();
    Broadcaster b = new DummyBroadcaster();
    
    b.fire();
    b.addListener(l);
    b.fire();
    b.fire();
    b.removeListener(l);
    b.fire();
    b.fire();
    b.fire();
    b.fire();
    
    Assert.assertTrue(cnt == 2);
  }
  
}
